/**
 * Log Watch uitlity
 * @Author: jiangcheng198745@hotmail.com
 * @Date: 2016/07/30
 */
'use strict';

import messageLogger  from './message.gulp';

function logWatch(event) {
    messageLogger('*** Files' + event.path + ' was ' + event.type +', running tasks...');
    let cwd = process.cwd();
    let path = event.path.substr(cwd.length + 1).replace(/\\/g, '/');
    let pathArray = path.split('/');
    let appIndex = pathArray.indexOf('modules' + 1);
    let parentIndex = pathArray.length - 1;

    var parentDirectory = pathArray.slice(appIndex, parentIndex).join('/');

    return  {
        testFiles: [
            'test/' + parentDirectory + '/**.spec.js',
            'app/**/' + parentDirectory + '/**.spec.js'
        ],
        changedFiles: path
    }
}

module.exports = logWatch;